package general;

/**
 *
 * @author foliveira
 */
public abstract class MessageHandler{
  private MessageHandler next;
  private RequestBuilder request;
  
  public final void setNext(MessageHandler next){
    
    this.next=next;
    
  }
  
  public final void handlerRequest(UDPMessage message){
    if(accept(message)){
      doHandle(message);
    }else if(this.next != null){
      this.next.handlerRequest(message);
    }
  }
    
  public abstract boolean accept(UDPMessage message);
  public abstract void doHandle(UDPMessage message);

  public Request getRequest() {
    return request.getRequest();
  }

  public void setRequest(String request) {
    this.request = new RequestBuilder(request);
  }
  
  
}
